﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.woodsoft.core;
using com.woodsoft.core.Files;
using EQ1.Elements;
using EQ1.Objects;

namespace EQ1.Templates {
  public class FrameTemplate : UIClass , IUIElement<FrameTemplate> {
    public FrameTemplate ( UIDocument doc , string name )
      : base( doc , name ) {
      this.OverlapLeft = 0;
      this.OverlapTop = 0;
      this.OverlapRight = 0;
      this.OverlapBottom = 0;
    }
    public FrameTemplate ( UIDocument doc )
      : this( doc , "FrameTemplate" ) {
    }

    #region IUIElement<FrameTemplate> Members
    public void Copy ( FrameTemplate val ) {
      base.Copy( val );

      this.OverlapLeft = val.OverlapLeft;
      this.OverlapTop = val.OverlapTop;
      this.OverlapRight = val.OverlapRight;
      this.OverlapBottom = val.OverlapBottom;
      
      if( !string.IsNullOrEmpty( val.TopLeft ) )
        this.TopLeft = val.TopLeft;
      if( !string.IsNullOrEmpty( val.Top ) )
        this.Top = val.Top;
      if( !string.IsNullOrEmpty( val.TopRight ) )
        this.TopRight = val.TopRight;
      if( !string.IsNullOrEmpty( val.RightTop ) )
        this.RightTop = val.RightTop;
      if( !string.IsNullOrEmpty( val.Right ) )
        this.Right = val.Right;
      if( !string.IsNullOrEmpty( val.RightBottom ) )
        this.RightBottom = val.RightBottom;
      if( !string.IsNullOrEmpty( val.BottomRight ) )
        this.BottomRight = val.BottomRight;
      if( !string.IsNullOrEmpty( val.Bottom ) )
        this.Bottom = val.Bottom;
      if( !string.IsNullOrEmpty( val.BottomLeft ) )
        this.BottomLeft = val.BottomLeft;
      if( !string.IsNullOrEmpty( val.LeftBottom ) )
        this.LeftBottom = val.LeftBottom;
      if( !string.IsNullOrEmpty( val.Left ) )
        this.Left = val.Left;
      if( !string.IsNullOrEmpty( val.LeftTop ) )
        this.LeftTop = val.LeftTop;
      if( !string.IsNullOrEmpty( val.Middle ) )
        this.Middle = val.Middle;
    }
    public void Validate ( FrameTemplate val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        FrameTemplate el = new FrameTemplate( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }

    #endregion
    
    public string TopLeft {
      get {
        return this.GetElement( "TopLeft" ).InnerText;
      }
      set {
        this.Validate( "TopLeft" , value );
      }
    }
    public string Top {
      get {
        return this.GetElement( "Top" ).InnerText;
      }
      set {
        this.Validate( "Top" , value );
      }
    }
    public string TopRight {
      get {
        return this.GetElement( "TopRight" ).InnerText;
      }
      set {
        this.Validate( "TopRight" , value );
      }
    }
    public string RightTop {
      get {
        return this.GetElement( "RightTop" ).InnerText;
      }
      set {
        this.Validate( "RightTop" , value );
      }
    }
    public string Right {
      get {
        return this.GetElement( "Right" ).InnerText;
      }
      set {
        this.Validate( "Right" , value );
      }
    }
    public string RightBottom {
      get {
        return this.GetElement( "RightBottom" ).InnerText;
      }
      set {
        this.Validate( "RightBottom" , value );
      }
    }
    public string BottomRight {
      get {
        return this.GetElement( "BottomRight" ).InnerText;
      }
      set {
        this.Validate( "BottomRight" , value );
      }
    }
    public string Bottom {
      get {
        return this.GetElement( "Bottom" ).InnerText;
      }
      set {
        this.Validate( "Bottom" , value );
      }
    }
    public string BottomLeft {
      get {
        return this.GetElement( "BottomLeft" ).InnerText;
      }
      set {
        this.Validate( "BottomLeft" , value );
      }
    }
    public string LeftBottom {
      get {
        return this.GetElement( "LeftBottom" ).InnerText;
      }
      set {
        this.Validate( "LeftBottom" , value );
      }
    }
    public string Left {
      get {
        return this.GetElement( "Left" ).InnerText;
      }
      set {
        this.Validate( "Left" , value );
      }
    }
    public string LeftTop {
      get {
        return this.GetElement( "LeftTop" ).InnerText;
      }
      set {
        this.Validate( "LeftTop" , value );
      }
    }
    public string Middle {
      get {
        return this.GetElement( "Middle" ).InnerText;
      }
      set {
        this.Validate( "Middle" , value );
      }
    }
    public int OverlapLeft {
      get {
        return int.Parse( this.GetElement( "OverlapLeft" ).InnerText );
      }
      set {
        this.Validate( "OverlapLeft" , value.ToString() );
      }
    }
    public int OverlapTop {
      get {
        return int.Parse( this.GetElement( "OverlapTop" ).InnerText );
      }
      set {
        this.Validate( "OverlapTop" , value.ToString() );
      }
    }
    public int OverlapRight {
      get {
        return int.Parse( this.GetElement( "OverlapRight" ).InnerText );
      }
      set {
        this.Validate( "OverlapRight" , value.ToString() );
      }
    }
    public int OverlapBottom {
      get {
        return int.Parse( this.GetElement( "OverlapBottom" ).InnerText );
      }
      set {
        this.Validate( "OverlapBottom" , value.ToString() );
      }
    }


  }
}
